-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KTOR-7584 HTMX extension for Ktor #4553
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally, it is here :)
ktor-server/ktor-server-plugins/ktor-server-htmx/common/src/io/ktor/server/htmx/HxRouting.kt
Show resolved
Hide resolved
ktor-server/ktor-server-plugins/ktor-server-htmx/common/src/io/ktor/server/htmx/HxRouting.kt
Outdated
Show resolved
Hide resolved
ktor-server/ktor-server-plugins/ktor-server-htmx/common/test/io/ktor/server/htmx/HtmxTest.kt
Outdated
Show resolved
Hide resolved
ktor-server/ktor-server-plugins/ktor-server-htmx/common/src/io/ktor/server/htmx/HxAttributes.kt
Outdated
Show resolved
Hide resolved
ktor-shared/ktor-htmx/common/src/io/ktor/htmx/HxAttributeKeys.kt
Outdated
Show resolved
Hide resolved
ktor-server/ktor-server-plugins/ktor-server-htmx/common/src/io/ktor/server/htmx/HxHeaders.kt
Outdated
Show resolved
Hide resolved
public val on: On | ||
get() = On(map) | ||
|
||
public fun on(event: String, script: String) { | ||
map["hx-on:$event"] = script | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember what we decided here. Keep both options of syntax?
on["event] = "script"
on("event", "script")
public var pushUrl: String? by HxAttributeKeys.PushUrl | ||
public var select: String? by HxAttributeKeys.Select | ||
public var selectOob: String? by HxAttributeKeys.SelectOob | ||
public var swap: String? by HxAttributeKeys.Swap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've had type-safe implementations for some of these fields. Will it be part of some future PR?
7c22c8a
to
f555d1a
Compare
2c3b4d8
to
4a59355
Compare
466444a
to
0767037
Compare
0767037
to
ffafe9c
Compare
/** | ||
* Sub-routes only apply to a specific HX-Target header. | ||
*/ | ||
public fun target(expectedTrigger: String, body: Route.() -> Unit): Route = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public fun target(expectedTrigger: String, body: Route.() -> Unit): Route = | |
public fun target(expectedTarget: String, body: Route.() -> Unit): Route = |
} | ||
|
||
/** | ||
* Simplifies property access delegation for HxAttributes when setting attribute values from a string constant. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor. Probably we could drop "HxAttributes" from the description?
84bbd03
to
6c7cca9
Compare
6c7cca9
to
0fba7be
Compare
0fba7be
to
af2a880
Compare
af2a880
to
e2b593e
Compare
This is amazing. Nice work! 🎊
@bjhham Do you know if that is being tracked anywhere? It would be really useful with the HTMX plugin where we often respond with just a |
Here it is: KTOR-8195 Partial HTML response |
Subsystem
Server, New plugin
Motivation
KTOR-7584 First-class HTMX support
Solution
This extends the routing and HTML builder DSL with some handy HTMX helpers. I tried to ere on the conservative side here by not including everything and adding an experimental flag so we can change things later after testing. We don't have the HTML fragments extension yet in the HTML DSL, but you can still do everything you need using valid HTML and attributes.